package com.intct.hbase.ddl;

import com.intct.util.ConnectionHBaseUtils;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;

import java.io.IOException;

/**
 * @author gufg
 * @since 2025/6/12
 */
public class DropTable {
    public static void main(String[] args) throws IOException {
        // 连接HBase
        Connection connection = ConnectionHBaseUtils.getConnection();

        // 获取admin实例
        Admin admin = connection.getAdmin();

        TableName tableName = TableName.valueOf("intct_80_api", "t4");
        try {
        // 判断表是否存
        if (admin.tableExists(tableName)) {
            // 表是否已禁用
            if (!admin.isTableDisabled(tableName)) {
                    // 禁用表
                    admin.disableTable(tableName);
                }
                // 删除表
                admin.deleteTable(tableName);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 关闭资源
            if (admin != null) {
                admin.close();
            }
        }
    }
}
